package com.foreknow.ex.oop;
/*
* 对象分组：数组中可以存对象
* */
public class ObjectArray {
    public void getAllMessage(Student[] array) {
        for (int i = 0; i < array.length; i++) {
            Student s = array[i];
            System.out.println(s.getName() + "---" + s.getAge());
        }
        System.out.println("--------------------------------");
        for (Student ss : array) {//增强for循环foreach
            System.out.println(ss.getName() + "---" + ss.getAge());
        }
    }
    public Student []getALL(){
        //1.创建一个Student类型的容器
        Student[] array= new Student[2];
        //2.创建两个学生对象
        Student s1= new Student();
        s1.setName("tom");
        s1.setAge(20);
        Student s2=new Student();
        s2.setName("fender");
        s2.setAge(30);
        //3.将对象保存在数组中
        array[0] = s1;
        array[1] = s2;
        return array;
    }
    public static void main(String[] args) {
        //创建ObjectArray类的对象
        ObjectArray objectArray = new ObjectArray();
        Student[] sss = objectArray.getALL();
        for (Student student : sss) {
            System.out.println(student.getName() + "---" + student.getAge());
        }


        
        //调用ObjectArray对象中的方法


        //objectArray.getAllMessage(array);
        //4.遍历数组获取到数组中的Student对象信息

    }
}
